package com.weixin.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.weixin.bean.Student;
import com.weixin.mapper.StudentMapper;
import com.weixin.service.StudentService;
import com.weixin.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @GetMapping("/list")
    public R list(int pageNumber, int pageSize) {
        List<Student> students = studentService.selectAll(pageNumber,pageSize);
        long total = ((Page) students).getTotal();
        return R.ok().put("total",total).put("rows",students);
    }

    @PostMapping("/remove/{id}")
    public R remove(@PathVariable("id") int id) {
        int i = studentService.deleteByPrimaryKey(id);
        if (i > 0) {
            return R.ok("删除成功");
        }
        return R.error();
    }

}
